<?php

class GetContact
{
	private $sugar_client;
	private $wsdl;
	
	/* Constructor */
	public function __Construct($arg_wsdl)
	{
		$this->wsdl = $arg_wsdl;
		$this->sugar_client = new nusoapclient($arg_wsdl, true);
	}
	
	public function getContactenFromCriteria($arg_naam)
	{
		$contacten = $this->getContacten();
		
		$contactenArray = array();
		
		foreach($contacten as $contact)
		{
			$naam = $contact->getFullName();

			if(strlen(strpbrk($naam, $arg_naam.'%'))>0)
			{
				$contactenArray[] = $contact;
			}
		}
		
		return $contactenArray;
	}
	
	/* Geef een array van alle contacten terug */
	public function getContacten()
	{
		$session_id = $_SESSION['session'];
		$set_entry_params = array(
								  'session' => $session_id,
								  'module_name' => 'st_Contact',
								  'query' => '',
								  'order_by' => '',
								  'select_fields'=>array(
															'id',
															'name',
															'lastname',
															'betweentf',
															'functiontf',
															'email',
															'phone_number',
															'description',
															'bedrijf_id',
															'contactpersoon',
															'bedrijfsbegeleider',
															'active'
														),
								  'deleted' => false
								  );
		
		//Parse de "ruwe" data naar objecten en geef deze vervolgens terug
		$parser = new Parser($this->wsdl);
		$result_list = $this->sugar_client->call('get_entry_list',$set_entry_params);
		$result = $parser->setResult($result_list);
		
		return $parser->getContactArray();
	}
	
	public function getContact($arg_contact_id)
	{
		$session_id = $_SESSION['session'];
		$set_entry_params = array(
								  'session' => $session_id,
								  'module_name' => 'st_Contact',
								  'id' => $arg_contact_id,
								  'select_fields'=>array(
															'id',
															'name',
															'lastname',
															'betweentf',
															'functiontf',
															'email',
															'phone_number',
															'description',
															'bedrijf_id',
															'contactpersoon',
															'bedrijfsbegeleider',
															'active'
														)
								  );
		
		//Parse de "ruwe" data naar objecten en geef deze vervolgens terug
		$parser = new Parser($this->wsdl);

		$parser->setResult($this->sugar_client->call('get_entry',$set_entry_params));
		
		$array = $parser->getContactArray();
		
		return $array[0];
	}
}

?>
